package com.beeasy.tools.bean;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class MapperHolder {



    private Map<Class, AbstractMapper> instanceMap = new ConcurrentHashMap<>();

    public AbstractMapper getAbstractMapper(MapperField mapperField){
        if (mapperField.mapper() == null) {
            return null;
        }
        return instanceMap.computeIfAbsent(mapperField.mapper(), k -> {
            try {
                return mapperField.mapper().newInstance();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            return null;
        })   ;
    }
}
